<?php

/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2016/3/25
 * Time: 17:16
 */
class Model_ShopUserBuy extends PhalApi_Model_NotORM{
  protected function getTableName($id){
    return 't_shopuserbuy';    //用户购买商户的记录
  }
  /*
   * 插入用户购买记录
   */
  public function makeOrder($phone,$shopId){
    return $this->getORM()->insert(array('userid'=>$phone,'shopid'=>$shopId,'createtime'=>time()));
  }
  /*
   * 获取用户今天下单次数(可抽奖次数)
   */
  public function getTodayOrders($phone,$shopId){
    return $this->getORM()->select('count(*) count')
      ->where('userid',$phone)
      ->where('shopid',$shopId)
      ->where('createtime<?',strtotime(date("Y-m-d",strtotime("+1 day"))))
      ->where('createtime>=?',strtotime(date("Y-m-d")))
      ->fetchOne();
  }
}